//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.TridentModelSL
{
    using System;
    using System.Collections.Generic;
    using service = Microsoft.Research.ScientificWorkflow.TridentSilverlightService;

    /// <summary>
    /// 
    /// </summary>
    public class JobDescriptionModel
    {
        /// <summary>
        /// Gets or sets the name of the job.
        /// </summary>
        /// <value>The name of the job.</value>
        public string JobName { get; set; }

        /// <summary>
        /// Gets or sets the job notes.
        /// </summary>
        /// <value>The job notes.</value>
        public string JobNotes { get; set; }

        /// <summary>
        /// Gets or sets the workflow id.
        /// </summary>
        /// <value>The workflow id.</value>
        public Guid WorkflowId { get; set; }

        /// <summary>
        /// Gets or sets the scheduled by.
        /// </summary>
        /// <value>The scheduled by.</value>
        public UserModel ScheduledBy { get; set; }

        /// <summary>
        /// Gets or sets the node to execute on.
        /// </summary>
        /// <value>The node to execute on.</value>
        public NodeModel NodeToExecuteOn { get; set; }

        /// <summary>
        /// 
        /// </summary>
        private ICollection<ParameterDescriptionModel> requiredParameters = new List<ParameterDescriptionModel>();

        public ICollection<ParameterDescriptionModel> RequiredParameters
        {
            get { return this.requiredParameters; }
            set { this.requiredParameters = value; }
        }

        /// <summary>
        /// Convert to network model.
        /// </summary>
        /// <returns></returns>
        public service.JobDescriptionModel ToNetwork()
        {
            service.JobDescriptionModel jobDescriptionModel = new service.JobDescriptionModel();
            jobDescriptionModel.jobName = this.JobName;
            jobDescriptionModel.jobNotes = this.JobNotes;
            jobDescriptionModel.workflowId = this.WorkflowId;
            jobDescriptionModel.nodeToExecuteOn = this.NodeToExecuteOn.ToNetwork();

            jobDescriptionModel.RequiredParameters = new List<service.ParameterDescriptionModel>();
            foreach (ParameterDescriptionModel parameter in RequiredParameters)
            {
                jobDescriptionModel.RequiredParameters.Add(parameter.ToNetwork());
            }

            return jobDescriptionModel;
        }
    }
}
